package com.llkj.qingnianguoxue.adapter;

import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;
import com.llkj.qingnianguoxue.R;
import com.llkj.qingnianguoxue.bean.PreviousActionBean;
import com.llkj.qingnianguoxue.util.DisplayUtil;
import com.llkj.qingnianguoxue.util.ImageLoadingUtil;

import java.util.List;

/**
 * 我的活动
 */
public class MyActionsAdapter extends BaseQuickAdapter<PreviousActionBean.ActionBean, BaseViewHolder> {

    public MyActionsAdapter(int layoutResId, List<PreviousActionBean.ActionBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, PreviousActionBean.ActionBean item) {
        ImageView ivPic = baseViewHolder.getView(R.id.iv_action_pic);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) ivPic.getLayoutParams();
        params.width = DisplayUtil.getDensityWdith(mContext) - DisplayUtil.dip2px(mContext, 20);
        params.height = params.width * 291 / 710;

        ImageLoadingUtil.loadingUrlCenterCrop(ivPic, item.getActivityimg());
        baseViewHolder.setText(R.id.tv_title, item.getName());

        TextView tvState = baseViewHolder.getView(R.id.tv_state);
        if ("1".equals(item.getState())) {
            tvState.setText("报名中");
//            setTextColor(tvState, 1);
        } else if ("2".equals(item.getState())) {
            tvState.setText("已报名");
//            setTextColor(tvState, 2);
        } else if ("3".equals(item.getState())) {
            tvState.setText("已结束");
//            setTextColor(tvState, 0);
        }
        tvState.setTextColor(mContext.getResources().getColor(R.color.colorffffff));
    }

    private void setTextColor(TextView tv, int type) {
        if (type == 1) {
            tv.setTextColor(mContext.getResources().getColor(R.color.colorFE4A49));
        } else if (type == 2) {
            tv.setTextColor(mContext.getResources().getColor(R.color.color999999));
        } else {
            tv.setTextColor(mContext.getResources().getColor(R.color.color999999));
        }
    }
}
